<?php
	session_start( );
	require_once('connections/mysqlDB.php');
	$dbConn = new mysqli(HOST,USER,PWD,DB);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!--DVID=00001DE9-->
<HTML>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<LINK href="frmm.css" rel="stylesheet" type="text/css">
<title>慕主先鋒教會</title>
</head>
<?php
$regid=  $_SESSION['regid'];
$email =  $_SESSION['email'];
$fullname= $_SESSION['fullname']; 
?>
<body link=#3060c0 vlink=#3060c0>

<div id="container"> 
  <h1><img src="frmmtitlePic.jpg" width="785" height="75"></h1>


  <div id="thin-col">
登入名(Login as)<br><li><a href="con_registrant.php"><?php echo $_SESSION['fullname']; ?></a>
<p>

<a href=logout.php>登出(Logout)</a>
<hr color=#c0c0c0 size = 1>

特會報名<br>(Registration for)</b><li><?php echo $_SESSION['conferenceID']; ?>
<p>

    <!-- * Be sure to validate your HTML and CSS before including these buttons 
    		 * HTML Validator: http://webdesign.about.com/od/validators/l/bl_validation.htm#htmlvalidator
         * CSS Validator: http://webdesign.about.com/od/validators/l/bl_validation.htm#cssvalidator
    -->

<a href="con_newreg.php"><font size=-1>替別人報名<br>(New Registration)</font></a><br><br>
<a href="con_shareroom.php"><font size=-1>我可以分享床位 Share My Room<br></font></a><br>
<a href="con_findroom.php"><font size=-1>床位 Find A Room<br></font></a><br>
<a href="con_sharecar.php"><font size=-1>我可以分享車位 Car Share<br></font></a><br>
<p>

</div>

<div id="thick-col">

<?php
	$hotelId = $_POST["hotel"];
	$roomNumber = $_POST["room_number"];
	$roomCapacity = $_POST["room_capacity"];
	$availability = $roomCapacity - 1;
	$checkinDate = date('Y-m-d', strtotime($_POST["checkin_date"]));
	$checkoutDate = date('Y-m-d', strtotime($_POST["checkout_date"]));
	$result = mysqli_query($dbConn, "select regid from registrant where email = '$email'");
	$row = mysqli_fetch_array($result);
	$ownerId = $row['regid'];
	//$result = mysqli_query($dbConn, "INSERT INTO SHARE_ROOM (NUMBER, HOTEL, OWNER, CAPACITY, AVAILABILITY, CHECKIN_DATE, CHECKOUT_DATE) VALUES
	//	('$roomNumber', '$hotelId', '$ownerId', '$roomCapacity', '$availability', '$checkinDate', '$checkoutDate')");
	if ($stmt = $dbConn->prepare("INSERT INTO SHARE_ROOM (NUMBER, HOTEL, OWNER, CAPACITY, AVAILABILITY, CHECKIN_DATE, CHECKOUT_DATE) VALUES
		('$roomNumber', '$hotelId', '$ownerId', '$roomCapacity', '$availability', '$checkinDate', '$checkoutDate')")) {
		$stmt->execute();
		$roomId=$stmt->insert_id;
	}
	
	if ($roomId == 0) {
		echo "<h1>Sharing A Room FAILED ...</h1>";
	} else {
		$result = mysqli_query($dbConn, "INSERT INTO ROOMMATE (ROOMID, REGID, ISOWNER) VALUES ('$roomId', '$ownerId', 1)");
		if (!$result) {
			echo "<h1>Sharing A Room FAILED ...</h1>";
		} else {
			header("location: con_shareroom.php");
		}
	}
?>

</div> <!-- end of green box ->

</div> <!-- end of container ->

</body>
</html>
